package pwd.allen.controller;

import com.alibaba.nacos.api.config.annotation.NacosProperty;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pwd.allen.service.IHelloService;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * @author pwdan
 * @create 2019-10-06 9:35
 **/
@RestController
@RequestMapping("nacos")
public class NacosController {

//    @DubboReference(version = "pwd-1.0")
//    private IHelloService helloService;
//
//    @GetMapping("/sayHello/{name}")
//    public Object sayHello(@PathVariable String name) {
//        return helloService.sayHello(name);
//    }

    @NacosValue(value = "${pwd.info}", autoRefreshed = true)
    private String info;
//    @Value("${pwd.num}") //@Value不会动态刷新
    @NacosValue("${pwd.num}") //不加autoRefreshed = true没法动态刷新
    private Integer num;

    @GetMapping("config")
    public Object sayHello(HttpServletRequest request) {
        HashMap<String, Object> resultMap = new HashMap<>(5);
        resultMap.put("info", info);
        resultMap.put("num", num);
        return resultMap;
    }

}
